package com.dgshanger.sanhxiaofeisc.mvp.presenter;

import com.dgshanger.sanhxiaofeisc.entity.BillEntity;
import com.dgshanger.sanhxiaofeisc.mvp.contract.BillDetailContract;
import com.dgshanger.sanhxiaofeisc.mvp.model.BillDetailModel;
import com.xx.baseuilibrary.mvp.BaseRxMvpPresenter;
import com.xx.baseutilslibrary.network.rx.RxHttpObserver;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * BillDetailPresenter
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/5/9 17:57.
 */

public class BillDetailPresenter extends BaseRxMvpPresenter<BillDetailContract.Model, BillDetailContract.View> implements BillDetailContract.Presenter {
    @NotNull
    @Override
    protected BillDetailContract.Model createModel() {
        return new BillDetailModel();
    }

    @Override
    public void loadDetail() {
        if (getView() == null) {
            return;
        }
        String logId = getView().getLogId();
        getModel().loadDetail(logId, new RxHttpObserver<BillEntity>() {
            @Override
            public void onCompleted(@Nullable String msg, @Nullable BillEntity entity) {
                if (getView() == null)
                    return;
                getView().setDetails(entity);
            }

            @Override
            public void onError(@Nullable String error) {

            }

            @Override
            public void onLoadingStart() {
                attachObserver(this);
            }

            @Override
            public void onLoadingFinish() {

            }
        });
    }
}
